package com.whenjun.controller;


import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.idev.excel.FastExcel;
import cn.idev.excel.FastExcelFactory;
import com.whenjun.common.LoggerParent;
import com.whenjun.dto.kq.KqV2DTO;
import com.whenjun.service.impl.KqServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("kq")
@SaCheckPermission(value = "kq", orRole = "admin")
@Api(tags = "考勤管理-报表")
@SaCheckLogin
public class KqV2Controller extends LoggerParent {

    @Autowired
    private KqServiceImpl kqService;

    @GetMapping("/export/download")
    @ApiOperation(value = "导出考勤报表")
    public void download(HttpServletResponse response, String month) throws ParseException, IOException {
        kqService.download(response, month);
    }

    public static void main(String[] args) {
        List<KqV2DTO> dtoList = new ArrayList<>();

        for (int i = 0; i < 100; i++) {
            KqV2DTO dto = new KqV2DTO();
            dto.setPersonName("张三" + i);
            dto.setShouldArrive(10);
            dto.setActualArrive(10);
            dto.setLateCount(1);
            dto.setLateSumTime(10);
            dto.setEarlyCount(1);
            dto.setEarlySumTime(10);
            dto.setShouldSignCount(10);
            dto.setSignCount(10);
            dto.setSignOutCount(10);
            dto.setNoSignCount(10);
            dto.setNoSignOutCount(10);
            dto.setAbsenteeismCount(10);
            dto.setAbsenteeismTime1(10);
            dto.setJiabanAbsenteeismTime1(10);
            dto.setAbsenteeismTime2(10);
            dto.setJiabanAbsenteeismTime2(10);
            dto.setM8hNightCount(10);
            dto.setM12hNightCount(10);
            dtoList.add(dto);
        }

        // 生成 Excel
        String fileName = "demo.xlsx";
        // 创建一个名为“模板”的 sheet 页，并写入数据
        FastExcel.write(fileName, KqV2DTO.class).sheet("模板").doWrite(dtoList);


        System.out.println("生成成功！");
    }
}
